<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>mixin混入技术的应用</title>
</head>
<body>
    <div id="app">

    </div>
    <script src="vue.js"></script>
    <script>
        // 需求，一个模态框，一个提示框
        const toggleShow={
            data(){
                return{
                    isShow:false
                }
            },
            methods:{
                toggleShow(){
                    this.isShow=!this.isShow
                }
            }
        }
        // 模态框
        const Modal={
            template:`
                <div v-if='isShow'>
                    <h3>模态框组件</h3>
                </div>
            `,
           mixins:[toggleShow]
        }
        // 提示框
        const ToolTip={
            template:`
                <div v-if='isShow'>
                    <h2>提示框组件</h2>
                </div>
            `,
            mixins:[toggleShow]
        }
        new Vue({
            el:'#app',
            data:{

            },
            components:{
                Modal,
                ToolTip
            },
            template:`
                <div>
                    <button @click='handleModel'>模态框</button>
                    <button @click='handleToolTip'>提示框</button>
                    <Modal ref='modal'></Modal>
                    <ToolTip ref='toolTip'></ToolTip>
                </div>
            `,
            methods:{
                handleModel(){
                    this.$refs.modal.toggleShow();
                },
                handleToolTip(){
                    this.$refs.toolTip.toggleShow();
                }
            }
        })
    </script>
</body>
</html>